package com.ruoyi.spicfz.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.spicfz.domain.ExecutivesCompos;
import com.ruoyi.spicfz.service.IExecutivesComposService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 高管任职Controller
 * 
 * @author ruoyi
 * @date 2021-09-02
 */
@Controller
@RequestMapping("/spicfz/compos")
public class ExecutivesComposController extends BaseController
{
    private String prefix = "spicfz/compos";

    @Autowired
    private IExecutivesComposService executivesComposService;

    @RequiresPermissions("spicfz:compos:view")
    @GetMapping()
    public String compos()
    {
        return prefix + "/compos";
    }

    /**
     * 查询高管任职列表
     */
    @RequiresPermissions("spicfz:compos:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ExecutivesCompos executivesCompos)
    {
        startPage();
        List<ExecutivesCompos> list = executivesComposService.selectExecutivesComposList(executivesCompos);
        return getDataTable(list);
    }

    /**
     * 导出高管任职列表
     */
    @RequiresPermissions("spicfz:compos:export")
    @Log(title = "高管任职", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ExecutivesCompos executivesCompos)
    {
        List<ExecutivesCompos> list = executivesComposService.selectExecutivesComposList(executivesCompos);
        ExcelUtil<ExecutivesCompos> util = new ExcelUtil<ExecutivesCompos>(ExecutivesCompos.class);
        return util.exportExcel(list, "高管任职数据");
    }

    /**
     * 新增高管任职
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存高管任职
     */
    @RequiresPermissions("spicfz:compos:add")
    @Log(title = "高管任职", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ExecutivesCompos executivesCompos)
    {
        return toAjax(executivesComposService.insertExecutivesCompos(executivesCompos));
    }

    /**
     * 修改高管任职
     */
    @GetMapping("/edit/{executiveId}")
    public String edit(@PathVariable("executiveId") Long executiveId, ModelMap mmap)
    {
        ExecutivesCompos executivesCompos = executivesComposService.selectExecutivesComposById(executiveId);
        mmap.put("executivesCompos", executivesCompos);
        return prefix + "/edit";
    }

    /**
     * 修改保存高管任职
     */
    @RequiresPermissions("spicfz:compos:edit")
    @Log(title = "高管任职", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ExecutivesCompos executivesCompos)
    {
        return toAjax(executivesComposService.updateExecutivesCompos(executivesCompos));
    }

    /**
     * 删除高管任职
     */
    @RequiresPermissions("spicfz:compos:remove")
    @Log(title = "高管任职", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(executivesComposService.deleteExecutivesComposByIds(ids));
    }
}
